The subject invention relates generally to a system and method for determining voltage levels and, more particularly, relates to a method for determining voltage levels in a system having a microcontroller.
In embedded microcontroller applications, the ability to determine an analog voltage level is sometimes necessary. Examples of determining an/analog voltage level include reading sensor values for pressure, temperature, position, etc., in control and user interface systems as well as determining supply voltage levels in battery operated devices, such as remote controls. The determining of supply voltage levels in battery operated devices may be required, by way of example, for estimation of remaining battery capacity to be used, for automatic adjustment of features such as backlighting intensity settings to compensate for declining battery voltage, etc.
Where the microcontroller in question is equipped with a built-in analog to digital converter, a comparator with a reference voltage, or similar capability, determination of voltage levels can be directly and easily accomplished. However, many inexpensive microcontrollers omit built-in analog to digital converters for reasons of cost saving (i.e., low-cost microcontrollers). In the case of low-cost microcontrollers, one method commonly used to approximate a voltage level is to measure the charging time of a capacitor connected to the voltage of interest through a series resistor. As it is well known, the time dependent voltage (V(t)) measured across the capacitor during the charging cycle in such an arrangement can be expressed as:
 V(t)=Vo(1−e−t/RC)  (1)
Where:
                t=time in seconds from start of charging;        Vo=supply voltage;        R=resistance value;        C=capacitance value; and        e=the natural log base (2.71828 . . . ).Accordingly, if the time (t) taken to reach a predetermined voltage value (V′) can be measured, the value of the voltage source (Vo) can be calculated (for a known RC) as:Vo=V′/(1−e−t/RC).  (2)        
In the case of low-cost microcontrollers which support only digital inputs, this approach can be used by selecting the predetermined voltage value (V′) to be the voltage level at which a digital input port pin of the low-cost microcontroller transitions from a logic “0” to a logic “1.” Since the transition point between a logic “0” and a logic “1” is generally a known relative constant for a given microcontroller technology, connecting an input-enabled port pin to the capacitor and time stamping the point during the charging cycle when the input reading switches from a logic “0” to a logic “1” is all that is required. Prior Art FIG. 1 shows a typical circuit that may be used for this purpose. In the circuit illustrated in FIG. 1, in order to determine a voltage level (Vo), port pins P10 and P11 are first both set to the “output low” state (to fully discharge capacitor C1) and then, after an appropriate period of time, P11 is reversed to become a high impedance input port and allow charging of the capacitor to commence. The time (t) between switching P11 to input mode and its observed transition from a logic “0” to a logic “1” is measured and used to calculate the voltage (Vo) as described above.
Unfortunately, this approach cannot be used successfully in unregulated battery powered devices to determine the battery supply voltage level itself (or any other absolute voltage, for that matter). This is because the “0” to “1” logic transition point of an input port of a microcontroller is not an absolute value, but rather varies with the supply voltage Vdd. Specifically, the transition point Input High (VIN HIGH) is most often expressed as a ratio of Vdd, usually in the range 0.5 Vdd to 0.7 Vdd. Therefore, it will be appreciated that for a battery-powered (non-regulated) device, the previously described approach is only capable of determining a second voltage level as a ratio of Vdd—it cannot be used to determine an absolute voltage level. While this ratiometric approach is adequate for implementation of technologies such as FSR navigation pads and the like, it is not suitable for applications where the absolute value of Vdd is required such as, for example, backlight brightness adjustment. In this regard, attempting to solve equations (1) or (2) above for battery voltage measurement by substituting Vdd for Vo and 0.7 Vdd for V′ will quickly reveal that time (t) becomes a constant.
A further analog to digital voltage measuring device is disclosed in U.S. Pat. No. 6,348,798 wherein a voltage measuring circuit is used to measure a voltage level of an unknown voltage source. The measuring circuit includes a capacitor configured for storing a charge from the unknown voltage source and a switch, such as a transistor, is configured to discharge the capacitor after the capacitor has reached a known threshold voltage. A microcontroller controls the switch and measures the amount of time (t) required to charge the capacitor to the required threshold voltage. Undesirably, the disclosed circuit requires an external comparator, e.g., a Motorola MC33464H-27AT1 reset controller, which is used to determine when the threshold voltage is reached and to provide a state-change logic signal to the microcontroller to signify to the microcontroller the end of the measured time (t).